\documentclass[10pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\usepackage{fix-cm}
\usepackage{chngpage}
\usepackage{graphicx}
\usepackage{color}
\usepackage{makeidx}
\usepackage{longtable}
\usepackage{colortbl}
\usepackage[table]{xcolor}
\usepackage{underscore}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{float}
\usepackage{array}
\usepackage{datatool}
\usepackage{subfigure}
\usepackage{fancyhdr}
\usepackage[Bjarne]{fncychap}
\usepackage{listings}
\usepackage{bold-extra}
\usepackage{lettrine}
\usepackage{booktabs}
\usepackage{multirow}
\definecolor{seagreen}{RGB}{64,100,120}
\definecolor{darkpink}{RGB}{200,100,120}
\definecolor{light-gray}{gray}{0.85}
\definecolor{medium-gray}{gray}{0.5}
\usepackage[colorlinks=true,linkcolor=seagreen,citecolor=darkpink]{hyperref}
\usepackage{path}

%
% custom options
%
\renewcommand{\captionlabelfont}{\small \bf}
\renewcommand{\captionfont}{\small \it}
\setlength{\parindent}{0mm}
\setlength{\parskip}{.5\baselineskip}
\fancyhead{} % clear all header fields
\fancyhead[RO,LE]{\thepage}
\fancyhead[LO,RE]{\nouppercase{\rightmark}}
\fancyfoot{} % clear all footer fields
%\fancyfoot[LO,RE]{\slshape The Trampoline Handbook}
\fancyfoot[RO,LE]{\slshape\nouppercase{\leftmark}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}
\ChTitleVar{\raggedleft\Huge\sffamily}
\ChNameVar{\raggedleft\normalsize\sffamily}
\ChNumVar{\raggedleft\bfseries\Large\sffamily}

%
% C language options
%
\lstset{
  language=C,
  basicstyle=\ttfamily\footnotesize,
  commentstyle=\itshape\color{cyan}
}

%
% OIL language options
%
\lstdefinelanguage{OIL}
{
  morekeywords= {
	  RESOURCE, RESOURCEPROPERTY, STANDARD, INTERNAL, LINKED, LINKEDRESOURCE,
	  TASK, SCHEDULE, FULL, NONE, PRIORITY, EVENT, ISR, CATEGORY, OS, CPU, MEMMAP,
	  COMPILER, LINKER, SCRIPT, IOC, DATATYPENAME, DATATYPEPROPERTY, RECEIVER, SENDER, RCV_OSAPPLICATION, 	  RECEIVER_PULL_CB, ACTION, SENDER_ID, SND_OSAPPLICATION
	}
}

\lstset{
  language=OIL,
%  emph={
%    var,
%    expression,
%    string,
%    instruction_list,
%    template_file_name,
%    reader,
%    hierarchy
%  },
  emphstyle=\em,
  moredelim=[s]{"}{"},
  basicstyle=\ttfamily\small}

\lstdefinelanguage{goilTemplate}
{
  morekeywords= {
	  after,
	  before,
	  between,
	  block,
	  default,
	  do,
	  else,
	  elsif,
	  emptylist,
	  end,
	  error,
	  exists,
	  false,
	  for,
	  foreach,
	  from,
	  here,
	  let,
	  loop,
	  no,
	  if,
	  in,
	  mod,
	  not,
	  or,
	  prefixedby,
	  template,
	  then,
	  to,
	  true,
	  yes,
	  warning,
	  while,
	  write,
	  !,
	  ?
	}
}

\lstset{
  language=goilTemplate,
  emph={
    var,
    expression,
    string,
    instruction_list,
    template_file_name,
    reader,
    hierarchy
  },
  emphstyle=\em,
  moredelim=[s][\color{blue}]{\%}{\%},
  moredelim=[s]{"}{"},
  morecomment=[l][\color{medium-gray}\itshape]{\#},
  basicstyle=\ttfamily\small,
  morekeywords=\bfseries
}
%
% Commands for paragraph types
%
%\newcommand{\note}[1]{\vspace{1mm}\fbox{\begin{minipage}[t]{.1\linewidth}{\bfseries Note:}\end{minipage}%
%\hfill\begin{minipage}[t]{.885\linewidth}#1\end{minipage}}\vspace{1mm}}
\newcommand{\note}[1]{%
\hspace{-12.4mm}
\rowcolors{1}{white}{white}
\begin{tabular}[b]{m{5mm}|m{\linewidth}}
\includegraphics[width=6mm,angle=45]{pictures/note} & #1\\
\end{tabular}
}
\newcommand{\warning}[1]{%
\hspace{-14.2mm}
\rowcolors{1}{white}{light-gray}
\begin{tabular}[b]{m{7mm}|m{\linewidth}}
\includegraphics[width=7mm]{pictures/warn} & #1\\
\end{tabular}
}
%
% Commands for inline formatting of C computing language
%
\newcommand{\argu}[1]{{\ttfamily #1}}
\newcommand{\ctype}[1]{{\small\ttfamily #1}}
\newcommand{\cdata}[1]{{\ttfamily #1}}
\newcommand{\var}[1]{{\ttfamily\em #1}}
\newcommand{\va}{\small\ttfamily\em}
\newcommand{\cfunction}[1]{{\ttfamily #1}}
\newcommand{\cmacro}[1]{{\small\ttfamily #1}}
\newcommand{\constant}[1]{{\small\ttfamily #1}}
\newcommand{\oilobj}[1]{{\small\ttfamily #1}}
\newcommand{\oilattr}[1]{{\small\ttfamily #1}}
\newcommand{\oilval}[1]{{\small\ttfamily #1}}
\newcommand{\member}[1]{{\small\ttfamily #1}}
\newcommand{\mem}{\small\ttfamily}
\newcommand{\tool}[1]{{\em #1}}

%
% Commands for other formatting
%
\newcommand{\file}[1]{{\ttfamily `#1'}}
\newcommand{\envvar}[1]{{\footnotesize\sffamily #1}}
\newcommand{\longprogramopt}[1]{{\ttfamily --#1}}
\newcommand{\programopt}[1]{{\ttfamily -#1}}
\newcommand{\strong}[1]{{\bf #1}}
\newcommand{\ie}{i.e.}
\newcommand{\asfct}[1]{\texttt{#1}}
\newcommand{\hex}[1]{\texttt{#1$_H$}}
\newcommand{\reg}[1]{\textit{#1}}
\newcommand{\dreg}[1]{{\small\ttfamily #1}}
\newcommand{\idxconfflag}[1]{{\footnotesize\ttfamily #1}\index{Configuration macros!#1}\index{#1}}
\newcommand{\toreplace}[1]{{\footnotesize $<$}#1{\footnotesize $>$}}
%\newcommand{\figcaption}[2]{\textit{\caption{\small #1}}\label{#2}}
\newcommand{\goil}{\tool{goil}\index{goil, The oil compiler of Trampoline}}
\newcommand{\process}{process\index{process, a task, basic or extended, or an ISR category 2}}
\newcommand{\sysgen}{system generation tool\index{system generation tool, the tool that takes as an input a description of the system (in OIL or in XML) to generate the corresponding .c and .h files.}}
\newcommand{\stringlit}[1]{{\small\ttfamily "{#1}"}}
\newcommand{\character}[1]{{\small\ttfamily `{#1}'}}
\newcommand{\api}[1]{\cfunction{#1}\index{#1}}
\newcommand{\osek}{OSEK}
\newcommand{\autosar}{{\small AUTOSAR}}
\newenvironment{penum}{
\begin{enumerate}
  \setlength{\itemsep}{1pt}
  \setlength{\parskip}{0pt}
  \setlength{\parsep}{0pt}
}{\end{enumerate}}
\newenvironment{pitemize}{
\begin{itemize}
  \setlength{\itemsep}{1pt}
  \setlength{\parskip}{0pt}
  \setlength{\parsep}{0pt}
}{\end{itemize}}

%
% Graphic symbols for scheduling diagrams
%
\newcommand{\activate}{\includegraphics[height=9pt]{pictures/activate.pdf}}
\newcommand{\terminate}{\includegraphics[height=9pt]{pictures/terminate.pdf}}

%
% states of a task
%
\newcommand{\RUNNING}{\constant{RUNNING}\index{RUNNING, state of a task}}
\newcommand{\READY}{\constant{READY}\index{READY, state of a task}}
\newcommand{\SUSPENDED}{\constant{SUSPENDED}\index{SUSPENDED, state of a task}}
\newcommand{\WAITING}{\constant{WAITING}\index{WAITING, state of a task}}
\newcommand{\AUTOSTART}{\constant{AUTOSTART}\index{AUTOSTART, state of a task}}
\newcommand{\READYANDNEW}{\constant{READY\_AND\_NEW}\index{READY_AND_NEW, state of a task}}

%
% Kind of task
%
\newcommand{\BASIC}{\constant{BASIC}\index{BASIC, compilation with no extended error checking}}
\newcommand{\EXTENDED}{\constant{EXTENDED}\index{EXTENDED, compilation with extended error checking}}

%
% result codes
%
\newcommand{\OK}{E\_OK}
\newcommand{\OSID}{E\_OS\_ID}
\newcommand{\OSLIMIT}{E\_OS\_LIMIT}
\newcommand{\OSRESOURCE}{E\_OS\_RESOURCE}
\newcommand{\OSCALLLEVEL}{E\_OS\_CALLEVEL}
\newcommand{\OSPROTECTIONMEMORY}{E\_OS\_PROTECTION\_MEMORY}
\newcommand{\OSACCESS}{E\_OS\_ACCESS}
\newcommand{\OSSTATE}{E\_OS\_STATE}

%
% Scalability class
%
\newcommand{\SC}[1]{scalability class #1}

%
% OIL attribute
%
\newcommand{\PRIORITY}{PRIORITY\index{PRIORITY}}
\newcommand{\SCHEDULE}{SCHEDULE\index{SCHEDULE}}
\newcommand{\TRUE}{{\small\ttfamily TRUE}}
\newcommand{\FALSE}{{\small\ttfamily FALSE}}

%
% Conf macros
%
\newcommand{\YES}{{\small\ttfamily YES}}
\newcommand{\NO}{{\small\ttfamily NO}}

%
% environment and commands to describe system services
%
\newcommand{\servicename}{}
\newcommand{\apiname}{}
\newcommand{\servicedescription}{}
\newcommand{\servicereturn}{}
\DTLnewdb{argDB}
\DTLnewdb{resDB}
\newenvironment{service}[2]{%
  \subsection{#1}\label{api:#1}\index{#1}%
  \renewcommand{\servicename}{#1}%
  \renewcommand{\apiname}{\api{#1}}%
  \renewcommand{\servicereturn}{#2}
  \DTLcleardb{argDB}
  \DTLcleardb{resDB}
}{
 
%  \vspace{1mm}
  {\bf Prototype of \servicename:}\nopagebreak
  
  {\tt\if\servicereturn\empty\relax\else\servicereturn\ \fi}{\tt \servicename(%
  \DTLifdbempty{argDB}{void}{%
    \DTLforeach*{argDB}{\argumenttype=type,\argumentname=name}{%
      \DTLiffirstrow{}{, }\argumenttype\ \argumentname%
    }%
  });}

  \DTLifdbempty{argDB}{}{
%    \vspace{1mm}
    {\bf Arguments of \servicename:}\nopagebreak
  
    \DTLforeach*{argDB}{\argumenttype=type,\argumentname=name,\argumentdesc=desc}{%
      \par\begingroup\hangindent=2em\hangafter=1 {\ttfamily\argumentname}\hspace{1em}\argumentdesc.\par\endgroup
    }
  }
  
  \DTLifdbempty{resDB}{}{
%    \vspace{1mm}
    {\bf Status codes returned by \servicename:}\nopagebreak
  
    \DTLforeach*{resDB}{\statusres=value,\statusdesc=desc,\statusstatus=status}{%
      \par\begingroup\hangindent=2em\hangafter=1 {\ttfamily\statusres}\hspace{1em}\statusdesc\ (\statusstatus).\par\endgroup
    }
  }
}

\newcommand{\argument}[3]{%
  \DTLnewrow{argDB}
  \DTLnewdbentry{argDB}{type}{#1}
  \DTLnewdbentry{argDB}{name}{#2}
  \DTLnewdbentry{argDB}{desc}{#3}
}

\newcommand{\resultcode}[2]{%
  \DTLnewrow{resDB}
  \DTLnewdbentry{resDB}{value}{#1}
  \DTLnewdbentry{resDB}{desc}{#2}
  \DTLnewdbentry{resDB}{status}{extended and standard}
}
  
\newcommand{\resultcodeauto}[2]{%
  \DTLnewrow{resDB}
  \DTLnewdbentry{resDB}{value}{#1}
  \DTLnewdbentry{resDB}{desc}{#2}
  \DTLnewdbentry{resDB}{status}{\AUTOSAR, extended and standard}
}
  
\newcommand{\resultcodeext}[2]{%
  \DTLnewrow{resDB}
  \DTLnewdbentry{resDB}{value}{#1}
  \DTLnewdbentry{resDB}{desc}{#2}
  \DTLnewdbentry{resDB}{status}{extended only}
}

\newcommand{\resultcodeautoext}[2]{%
  \DTLnewrow{resDB}
  \DTLnewdbentry{resDB}{value}{#1}
  \DTLnewdbentry{resDB}{desc}{#2}
  \DTLnewdbentry{resDB}{status}{\AUTOSAR, extended only}
}

\newcommand{\resultcodeMP}[2]{%
  \DTLnewrow{resDB}
  \DTLnewdbentry{resDB}{value}{#1}
  \DTLnewdbentry{resDB}{desc}{#2}
  \DTLnewdbentry{resDB}{status}{extended + \autosar\ \SC{3} and \SC{4} only}
}

%
% sorted table
%
\DTLnewdb{tableDB}
\newenvironment{sortedtable}[1]{%
  \DTLcleardb{tableDB}
  \begin{longtable}{#1}
}{
\DTLsort*{name}{tableDB}%
\DTLforeach*{tableDB}{%
\colname=name,\coltype=type,\coldesc=desc}{%
\DTLiffirstrow{\\\hline\endhead}{\\}%
\colname&\coltype&\coldesc}%
\end{longtable}
%\DTLdisplaylongdb{tableDB}
}
\newcommand{\sortline}[3]{%
  \DTLnewrow{tableDB}%
  \DTLnewdbentry{tableDB}{name}{#1}%
  \DTLnewdbentry{tableDB}{type}{#2}%
  \DTLnewdbentry{tableDB}{desc}{#3}%
}
%
% Here we go
%

%\includeonly{porting}

\title{The Trampoline handbook}
\author{Jean-Luc B\'echennec\\Florent Pavin\\Pierre Molinaro}

\makeindex

\begin{document}
\begin{titlepage}
\begin{minipage}[t]{1.1\linewidth}
\rule{\linewidth}{3pt}
\fontsize{40}{42}\selectfont\raggedleft\sffamily\bfseries The Trampoline Handbook

\vspace{2cm}\Large release 2.0

\vspace{2cm}
\large
Jean-Luc Béchennec\\
Mikaël Briday\\
Sébastien Faucou\\
Pierre Molinaro\\
Florent Pavin\\
\end{minipage}
\end{titlepage}
\setcounter{tocdepth}{2}
\tableofcontents


\part{The Real-Time Operating System}
\include{appmodes}
\include{tasks}
\include{resources}
\include{events}
\include{osapps}
\include{tp}
\include{st}
\include{com}
\include{ioc}
\include{memmapping}
\include{compilation}
\include{inside}
\include{porting}
\include{ports}

\part{The Goil system generator}
\include{templates}

\printindex
\bibliographystyle{plain}
\bibliography{trampoline}

\end{document}
